<!DOCTYPE html>
<html lang="en">

  <head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>字符串的解构</title>
  </head>

  <body>

  </body>
  <script>
    /* 
    字符串的解构
    */
    let str = "liu";
    let [x, y, z] = str;
    console.log(x, y, z); //l i u

    str[1] = 's'; //无法修改
    console.log(str); //liu
    console.log(str[1]); //l

    //应用：交换字符串的位置
    let str1 = "hello";
    let str2 = "world";

    [str2, str1] = [str1, str2]; //不需要变量直接利用ES6语法交换变量
    console.log(str1, str2); //world hello
  </script>

</html>